<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2"><br>
<input type="button" value="加" onclick="f1(1)">
<input type="button" value="减" onclick="f1(2)">
<input type="button" value="乘" onclick="f1(3)">
<input type="button" value="除" onclick="f1(4)">
<div>结果:</div>
<script>
    let i = document.querySelector("#i1");
    let i1 = document.querySelector("#i2");
    let d = document.querySelector("div");
    function f1(num) {
        if (isNaN(i.value) || isNaN(i1.value)) {
            d.innerText = "对";
            return;
        }

        switch (num) {
            case 1:
                d.innerText = parseFloat(i.value) + parseFloat(i1.value);break;
            case 2:
                d.innerText = parseFloat(i.value) - parseFloat(i1.value);break;
            case 3:
                d.innerText = parseFloat(i.value) * parseFloat(i1.value);break;
            case 4:
                d.innerText = parseFloat(i.value) / parseFloat(i1.value);break;
        }

    }


</script>

</body>
</html>